<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改商品')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-goodsSpu-edit" th:object="${goodsSpu}">
            <input name="id" th:field="*{id}" type="hidden">

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">食品名字：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">食品分类：</label>
                <div class="col-sm-8">
                    <select name="categoryFirst" class="form-control m-b" th:with="type=${@dict.getType('sys_goods_unit')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{categoryFirst}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">卖点：</label>
                <div class="col-sm-8">
                    <textarea name="sellPoint" class="form-control" required>[[*{sellPoint}]]</textarea>
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-3 control-label is-required">美食图片：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="picUrl" th:field="*{picUrl}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="picUrl" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">是否上架：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_enable')}">
                        <input type="radio" th:id="${'shelf_' + dict.dictCode}" name="shelf" th:value="${dict.dictValue}" th:field="*{shelf}" required>
                        <label th:for="${'shelf_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">销售价格：</label>
                <div class="col-sm-8">
                    <input name="salesPrice" th:field="*{salesPrice}" class="form-control" type="text" required>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />
    <th:block th:include="include :: jquery-cxselect-js"/>
    <script th:inline="javascript">

        var data = [[${categories}]];
        $('#element').cxSelect({
            selects: ['type', 'router'],
            jsonValue: 'v',
            data: data
        });

        var prefix = ctx + "food/goodsSpu";
        $("#form-goodsSpu-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-goodsSpu-edit').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true,
                showPreview: true,
                showUpload: false,
                uploadAsync: true,
                showRemove: false,
                dropZoneEnabled: false,
            }).on('filebatchselected', function (event, files) {//选中文件事件
            $(this).fileinput("upload");


            }).on('fileuploaded', function (event, data, previewId, index) {
                 $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });
    </script>
</body>
</html>
